﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ProjectTest.Models.Business
{
    public class QLNguoiDung
    {
        DBTestDataContext db = new DBTestDataContext();
        //them nhom nguoi dung
        public void Create(NguoiDung ND)
        {
            try
            {
                db.NguoiDungs.InsertOnSubmit(ND);
                db.SubmitChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //sau thong tin cau hoi
        public void Edit(NguoiDung NDEdited, int maND)
        {
            NguoiDung ND = db.NguoiDungs.SingleOrDefault(p => p.MaND == maND);
            try
            {
                UpdateInfo(ND, NDEdited);
                db.SubmitChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }

        private void UpdateInfo(NguoiDung ND, NguoiDung NDEdited)
        {
            ND.TenDangNhap = NDEdited.TenDangNhap;
            ND.MatKhau = NDEdited.MatKhau;
            ND.Email = NDEdited.Email;
            ND.MaNhomND = NDEdited.MaNhomND;
        }
        //xoa thong tin cau hoi theo ma
        public void Delete(int maND)
        {
            NguoiDung ND = db.NguoiDungs.SingleOrDefault(p => p.MaND == maND);
            try
            {
                db.NguoiDungs.DeleteOnSubmit(ND);
                db.SubmitChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }


    }
}